<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>A3 CCTV</title>
<meta name="description"
	content="profile : A3 CCTV for Google Hackfiar 2012">
<meta name="author" content="daclouds">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="stylesheets/reset.css">
<link rel="stylesheet" href="stylesheets/style.css">
<link rel="stylesheet" href="stylesheets/bootstrap-combined.min.css">
<link rel="stylesheet" href="stylesheets/bootstrap-responsive.css">
<script src="js/jquery-1.8.2.min.js"></script>
<script src="js/jquery.imagesloaded.js"></script>
<script src="js/jquery.wookmark.js"></script>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	$(".changeButton").click(function() {

		var trEle = $(this).parent().parent();
		var id = trEle.find(".attrId").text();
		var email = trEle.find(".name").text();
		
		
		var type = trEle.find(".attrType .active").val();
		var status = trEle.find(".attrStatus .active").val();

		$.post("/profile", {cmd:"change", id:id, email:email, type:type, status:status}, function(data) {
			var n = data.split(":");
			if (n.length != 2) alert("ERROR");
			else alert("성공");
			//alert(data + " " + type + " " + status);
		});
	});
});
</script>
</head>
<body>
	<div class="navbar navbar-inverse navbar-fixed-top">
		<div class="navbar-inner">
			<div class="container">
				<button type="button" class="btn btn-navbar" data-toggle="collapse"
					data-target=".nav-collapse">
					<span class="icon-bar"></span> <span class="icon-bar"></span><span
						class="icon-bar"></span>
				</button>
				<a class="brand" href="/">Hackfair 2012</a>
				<div class="nav-collapse collapse">
					<ul class="nav">
						<c:if test="${logoutUrl != null}">
							<li class=""><a href="#">${nickname}</a></li>
							<li class=""><a href="/profile">수신 설정</a><li>
						</c:if>
						<li class="">
							<c:if test="${logoutUrl == null}"><a href="${loginUrl}">로그인</a></c:if>
							<c:if test="${logoutUrl != null}"><a href="${logoutUrl}">로그아웃</a></c:if>
						</li>
					</ul>
				</div>
			</div>
		</div>
	</div>
	<div class="container-fluid">
		<header>
			<img src="https://developers.google.com/appengine/images/appengine-silver-120x30.gif" alt="Powered by Google App Engine" />
		</header>
		<div class="row-fluid">
			<table class="table table-striped">
				<thead>
					<tr>
						<th>id</th>
						<th>구분</th>
						<th>역할</th>
						<th>ON/OFF</th>
						<th>변경</th>
	                </tr>
              	</thead>
              	<tbody>
				<c:forEach var="device" items="${devices}">
                <tr>
	                <td class="attrId">${device.key.id}</td>
	                <td class="name">${device.properties.modelName}${device.properties.email}</td>
	                <td class="attrType">
		                <div class="btn-group" data-toggle="buttons-radio">
		                	<button type="button" class="btn <c:if test="${device.properties.type == 'VIEWER'}">active</c:if>" value="VIEWER">수신</button>
		                	<button type="button" class="btn <c:if test="${device.properties.type == 'TAKER'}">active</c:if>" value="TAKER">찍기</button>
		                </div>
	                </td>
	                <td class="attrStatus">
	                	<div class="btn-group" data-toggle="buttons-radio">
							<button type="button" class="btn <c:if test="${device.properties.status == 'ON'}">active</c:if>" value="ON">ON</button>
							<button type="button" class="btn <c:if test="${device.properties.status == 'OFF'}">active</c:if>" value="OFF">OFF</button>
						</div>   
	                </td>
	                <td><button class="btn btn-small btn-primary changeButton" type="button">변경</button></td>
                </tr>
                </c:forEach>
              </tbody>
            </table>
		</div>
		<footer></footer>
	</div>
</body>
</html>